<?php

	include_once('classes/view.php');
	View::displayHeader();
	
	if (isset($_SESSION['user_id']) && $_SESSION['user_id'] != '')
	{
		header("Location: index.php");		
	} else {
		if (!isset($_SESSION['try_login'])) $_SESSION['try_login'] = '' ;
		
		echo '
			<script type="text/javascript">
				function validateOnSubmit() {
					var elem;
					var myCountErrors=0;
								
					if (!validatePresent (document.forms.frmLogin.login,  \'inf_login\')) myCountErrors += 1;
					if (!validatePresent(document.forms.frmLogin.haslo, \'inf_haslo\')) myCountErrors += 1;
					
					if (myCountErrors > 1)  alert(\'Należy poprawić kilka pól.\');
					else if (myCountErrors == 1) alert(\'Należy poprawić jedno pole.\');
			
					return (myCountErrors == 0);
				};
			</script>
		
			<form name="frmLogin" method="post" onsubmit="return validateOnSubmit()" action="user_login.php">
				<div class="box">
					<h1> Wpisz login i hasło aby się zalogować</h1>
			  		<label>
						<span>Podaj login: </span>
						<input class="wpis" type="text" name="login" id="login" size="50" maxlength="30" onchange="validatePresent(this, \'inf_login\');" value="' . $_SESSION['try_login'] . '" />
						<i id="inf_login">Pole wymagane</i>
					</label>
					
					<label>
						<span>Podaj hasło: </span>
						<input class="wpis" type="password" name="haslo" id="haslo1" size="50" maxlength="50" />
						<i id="inf_haslo">Pole wymagane</i>
					</label>
					
					<label>
						<input class="button" type="Submit" name="Submit" value="Wyślij" />
					</label>
				</div>
			</form>
			<br /><br /><br />
		';
		View::displayFooter();
	}
	
	die();
?>